<?php
require_once('config.travel.php');
/** 
 * 有关景区的参数设置
 */
//require_once('config.mgafinstall.php');

class Travel_travelController extends Gaf_Controller_Action {
	protected  $travel;
	public function init(){
		parent::init();
		$this->travel=new travel();
	}
	/**
	 * @name 路线管理
	 * @menu 路线管理/路线列表
	 * @comment 路线管理，设置路线参数。
	 * @type WEB
	 */
	public function indexAction(){
		$tvlist=$this->travel->getTravelList();
		$this->view->tvlist=$tvlist;
		$this->view->MsgSection=$this->_getParam('errmsg');
		$p=$this->_getParam("p","0");
		$this->view->page=$p;
	}

	/**
	 * @name 增加线路
	 * @comment 增加线路
	*/
	public function addtravellineAction(){
		$rl=$this->travel->getRegionByLevel();
		$this->view->rl=$rl;
	}
	/**
	* @name 增加线路动作
	* @comment 增加线路动作
	*/
	public function doaddlineAction(){
		$this->_helper->viewRenderer->setNoRender();
		$paramArr['name']=$name=$this->_getParam('name');
		$paramArr['departure']=$departure=$this->_getParam('departure');
		$paramArr['destination']=$destination=$this->_getParam('destination');
		$paramArr['traveltool']=$traveltool=$this->_getParam('traveltool');
		$paramArr['type']=$type=$this->_getParam('type');
		$paramArr['season']=$season=$this->_getParam('season');
		$paramArr['pricetype']=$pricetype=$this->_getParam('pricetype');
		$paramArr['price']=$price=$this->_getParam('price');
		$paramArr['realprice']=$realprice=$this->_getParam('realprice');
		$paramArr['days']=$days=$this->_getParam('days');
		$paramArr['level']=$level=$this->_getParam('level');
		$paramArr['travelmemo']=$travelmemo=$this->_getParam('travelmemo');
		$paramArr['booknotes']=$booknotes=$this->_getParam('booknotes');
		$paramArr['linememo']=$linememo=$this->_getParam('linememo');
		$paramArr['memodetail']=$memodetail=$this->_getParam('memodetail');
		$this->travel->addTravelLine($paramArr);
		if($ret)	$this->_redirect("/travel/travel/index?errmsg=添加成功");
		else $this->_redirect("/travel/travel/index?errmsg=添加失败");
	}
	/**
	 * @name 获取线路详情
	 * @comment 获取线路详情
	*/
	public function gettraveldetailAction(){
		$tvid=$this->_getParam('tvid');
		$traveldetail=$this->travel->getTravelDetail($tvid);
		$this->view->traveldetail=$traveldetail;
		$depasite=$this->travel->getDepaSites($tvid);
		$destsite=$this->travel->getDestSites($tvid);
		$this->view->depasite=$depasite;
		$this->view->destsite=$destsite;
		$regions=$this->travel->getRegionByLevel();
		foreach ($regions as &$r){
			if($r['rid']==$depasite['departure'])	$r['seldepa']="selected";
			else $r['seldepa']="";
			if($r['rid']==$depasite['destination'])	$r['seldest']="selected";
			else $r['seldest']="";
		}
		$this->view->regions=$regions;
	}
	/**
	 * @name 修改线路信息
	 * @comment 修改线路信息
	*/
	public function doeditAction(){
		$this->_helper->viewRenderer->setNoRender();
		$tvid=$this->_getParam('tvid');
		$paramArr['name']=$name=$this->_getParam('name');
		$paramArr['departure']=$departure=$this->_getParam('departure');
		$paramArr['destination']=$destination=$this->_getParam('destination');
		$paramArr['traveltool']=$traveltool=$this->_getParam('traveltool');
		$paramArr['type']=$type=$this->_getParam('type');
		$paramArr['season']=$season=$this->_getParam('season');
		$paramArr['pricetype']=$pricetype=$this->_getParam('pricetype');
		$paramArr['price']=$price=$this->_getParam('price');
		$paramArr['realprice']=$realprice=$this->_getParam('realprice');
		$paramArr['days']=$days=$this->_getParam('days');
		$paramArr['level']=$level=$this->_getParam('level');
		$paramArr['travelmemo']=$travelmemo=$this->_getParam('travelmemo');
		$paramArr['booknotes']=$booknotes=$this->_getParam('booknotes');
		$paramArr['linememo']=$linememo=$this->_getParam('linememo');
		$paramArr['memodetail']=$memodetail=$this->_getParam('memodetail');
		$ret=$this->travel->doeditTravelLine($tvid,$paramArr);
		if($ret)	$this->_redirect("/travel/travel/index?errmsg=修改成功");
		else $this->_redirect("/travel/travel/index?errmsg=修改失败");
	}
	/**
	 * @name 删除线路
	 * @comment 删除线路
	 */
	public function deltravelAction(){
		$tvid=$this->_getParam('tvid');
		$this->travel->delTravel($tvid);
		$this->_redirect("/travel/travel/index?errmsg=删除成功");
	}
	/**
	 * @name 线路项目管理
	 * @comment 线路项目管理
	 */
	public function additemsAction(){
		$tvid=$this->_getParam('tvid');
		$itemlist=$this->travel->getAllItems($tvid);
		$this->view->itemlist=$itemlist;
		$this->view->tvid=$tvid;
		$this->view->MsgSection=$this->_getParam('errmsg');
		$p=$this->_getParam("p","0");
		$this->view->page=$p;
	}
	/**
	 * @name 添加项目 
	 * @comment 添加项目 
	*/
	public function doadditemsAction(){
		$tvid=$this->_getParam('tvid');
		$paramArr['itemname']=$name=$this->_getParam('itemname');
		$paramArr['price']=$price=$this->_getParam('price');
		$paramArr['type']=$type=$this->_getParam('type');
		$paramArr['memo']=$memo=$this->_getParam('memo');
		$ret=$this->travel->addItems($tvid,$paramArr);
		if($ret)	$this->_redirect("/travel/travel/additems?tvid=$tvid&errmsg=添加成功");
		else $this->_redirect("/travel/travel/additems?tvid=$tvid&errmsg=修改失败");
	}
	/**
	 * @name 删除项目
	 * @comment 删除项目
	*/
	public function delitemAction(){
		$this->_helper->viewRenderer->setNoRender();
		$tvid=$this->_getParam('tvid');
		$itemid=$this->_getParam('itemid');
		$ret=$this->travel->delItem($itemid);
		if($ret)	$this->_redirect("/travel/travel/additems?tvid=$tvid&errmsg=删除成功");
	}
	/**
	 * @name 修改项目
	 * @comment 修改项目
	*/
	public function edititemAction(){
		$itemid=$this->_getParam('itemid');
		$item=$this->travel->getItem($itemid);
		$this->view->item=$item;
	}
	/**
	 * @name 修改项目
	 * @comment 修改项目
	*/
	public function doedititemAction(){
		$this->_helper->viewRenderer->setNoRender();
		$tvid=$this->_getParam('tvid');
		$itemid=$this->_getParam('itemid');
		$paramArr['itemname']=$name=$this->_getParam('itemname');
		$paramArr['price']=$price=$this->_getParam('price');
		$paramArr['type']=$type=$this->_getParam('type');
		$paramArr['memo']=$memo=$this->_getParam('memo');
		$ret=$this->travel->editItem($itemid,$paramArr);
		if($ret)	$this->_redirect("/travel/travel/additems?tvid=$tvid&errmsg=修改成功");
	}
	/**
	 * @name 日程管理
	 * @comment 日程管理
	 */
	public function scheduleAction(){
		$tvid=$this->_getParam('tvid');
		$schlist=$this->travel->getScheduleList();
		$this->view->tvid=$tvid;
		$this->view->schlist=$schlist;
		$this->view->MsgSection=$this->_getParam('errmsg');
		$p=$this->_getParam("p","0");
		$this->view->page=$p;
	}
	/**
	 * @name 添加日程
	 * @comment 添加日程
	 */
	public function addscheduleAction(){
		$this->_helper->viewRenderer->setNoRender();
		$tvid=$this->_getParam('tvid');
		$paramArr['tvid']=$tvid;
		$paramArr['schedule']=$schedule=$this->_getParam('schedule');
		$paramArr['order']=$order=$this->_getParam('order');
		$paramArr['scheduledesc']=$scheduledesc=$this->_getParam('scheduledesc');
		$ret=$this->travel->addSchedule($paramArr);
		if($ret)	$this->_redirect("/travel/travel/schedule?tvid=$tvid&errmsg=添加成功");
	}
	/**
	 * @name 获取日程
	 * @comment 获取日程
	*/
	public function editschAction(){
		$id=$this->_getParam('id');
		$schedule=$this->travel->getSchById($id);
		$this->view->schedule=$schedule;
	}
	/**
	 * @name 修改日程
	 * @comment 修改日程
	*/
	public function doeditschAction(){
		$this->_helper->viewRenderer->setNoRender();
		$id=$this->_getParam('id');
		$paramArr['schedule']=$schedule=$this->_getParam('schedule');
		$paramArr['order']=$order=$this->_getParam('order');
		$paramArr['scheduledesc']=$scheduledesc=$this->_getParam('scheduledesc');
		$ret=$this->travel->editSchedule($id,$paramArr);
		if($ret)	$this->_redirect("/travel/travel/schedule?tvid=$tvid&errmsg=修改日程成功");
	}
}